<?php session_start();
  if (isset($_GET["order"])) $order = @$_GET["order"];
  if (isset($_GET["type"])) $ordtype = @$_GET["type"];

  if (isset($_POST["filter"])) $filter = @$_POST["filter"];
  if (isset($_POST["filter_field"])) $filterfield = @$_POST["filter_field"];
  $wholeonly = false;
  if (isset($_POST["wholeonly"])) $wholeonly = @$_POST["wholeonly"];

  if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
  if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
  if (!isset($filter) && isset($_SESSION["filter"])) $filter = $_SESSION["filter"];
  if (!isset($filterfield) && isset($_SESSION["filter_field"])) $filterfield = $_SESSION["filter_field"];

?>

<html>
<head>
<title>ADMIN -- fotografija</title>
<meta name="generator" http-equiv="content-type" content="text/html">
<style type="text/css">
  body {
    background-color: #FFFFFF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
  .bd {
    background-color: #FFFFFF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
  .tbl {
    background-color: #FFFFFF;
  }
  a:link { 
    color: #FF0000;
    font-family: Arial;
    font-size: 12px;
  }
  a:active { 
    color: #0000FF;
    font-family: Arial;
    font-size: 12px;
  }
  a:visited { 
    color: #800080;
    font-family: Arial;
    font-size: 12px;
  }
  .hr {
    background-color: #808080;
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  a.hr:link {
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  a.hr:active {
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  a.hr:visited {
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  .dr {
    background-color: #FFFFFF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
  .sr {
    background-color: #EEEEEE;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
</style>
</head>
<body>
<table class="bd" width="100%"><tr><td class="hr"><h2>Administracija Tattoo Portal</h2></td></tr></table>
<table width="100%">
<tr>

<td width="400px" valign="top">
<font face="Arial">
<a href="adminkomentari.php?a=reset">Admin_komentari</a>
</font>
<p><font face="Arial"><a href="autori.php?a=reset">Autori</a>
</font>
</p>
<p><font face="Arial"><a href="fotografija.php?a=reset">Fotografije</a>
</font>
</p>
<p><font face="Arial"><a href="komentari.php?a=reset">Komentari</a>
</font>
</p>
<p><font face="Arial"><a href="opremaoglasi.php?a=reset">Oprema_oglasi</a>
</font>
</p>
<p><font face="Arial"><a href="portal.php?a=reset">Portal</a>
</font>
</p>
<p><font face="Arial"><a href="privatneporuke.php?a=reset">Privatne_poruke</a>
</font>
</p>
<p><font face="Arial"><a href="reklame.php?a=reset">Reklame</a>
</font>
</p>
<p><font face="Arial"><a href="prodavnice.php?a=reset">Prodavnice</a>
</font>
</p>
<p><font face="Arial"><a href="wtagshoutbox.php?a=reset">Javni_chat</a></font></p>
<p><font face="Arial"><a href="registrovan_mail.php?a=reset">Registrovan_mail</a> 
</font> </p>
<p><font face="Arial"><a href="skljoc.php?a=reset">Likes</a> </font> </p> 
<p><font face="Arial"><a href="blog_poruke.php?a=reset">Magazin</a> </font> </p>
<p><font face="Arial"><a href="sajam_poruke.php?a=reset">Sajmovi</a>&nbsp; </font> </p>
</td>
<td width="5%">
</td>
<td bgcolor="#e0e0e0">
</td>
<td width="5%">
</td>
<td width="80%" valign="top">
<?php
error_reporting(0);
if ($_SESSION["adminusername"]=="")
{
    echo "Niste prijavljeni kao administrator";
    exit;
}
  $conn = connect();
  $showrecs = 50;
  $pagerange = 10;

  $a = @$_GET["a"];
  $recid = @$_GET["recid"];
  $page = @$_GET["page"];
  if (!isset($page)) $page = 1;

  $sql = @$_POST["sql"];

  switch ($sql) {
    case "insert":
      sql_insert();
      break;
    case "update":
      sql_update();
      break;
    case "delete":
      sql_delete();
      break;
  }

  switch ($a) {
    case "add":
      addrec();
      break;
    case "view":
      viewrec($recid);
      break;
    case "edit":
      editrec($recid);
      break;
    case "del":
      deleterec($recid);
      break;
    default:
      select();
      break;
  }

  if (isset($order)) $_SESSION["order"] = $order;
  if (isset($ordtype)) $_SESSION["type"] = $ordtype;
  if (isset($filter)) $_SESSION["filter"] = $filter;
  if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield;
  if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly;

  mysql_close($conn);
?>
</td></tr></table>
<table class="bd" width="100%"><tr><td class="hr">ADMIN panel</td></tr></table>
</body>
</html>

<?php function select()
  {
  global $a;
  global $showrecs;
  global $page;
  global $filter;
  global $filterfield;
  global $wholeonly;
  global $order;
  global $ordtype;


  if ($a == "reset") {
    $filter = "";
    $filterfield = "";
    $wholeonly = "";
    $order = "";
    $ordtype = "";
  }

  $checkstr = "";
  if ($wholeonly) $checkstr = " checked";
  if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }
  $res = sql_select();
  $count = sql_getrecordcount();
  if ($count % $showrecs != 0) {
    $pagecount = intval($count / $showrecs) + 1;
  }
  else {
    $pagecount = intval($count / $showrecs);
  }
  $startrec = $showrecs * ($page - 1);
  if ($startrec < $count) {mysql_data_seek($res, $startrec);}
  $reccount = min($showrecs * $page, $count);
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Tabela: fotografija</td></tr>
<tr><td>Prikaz podataka <?php echo $startrec + 1 ?> - <?php echo $reccount ?> od <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<form action="fotografija.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Kriterijum za filter</b>&nbsp;</td>
<td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td><select name="filter_field">
<option value="">Sva polja</option>
<option value="<?php echo "username" ?>"<?php if ($filterfield == "username") { echo "selected"; } ?>><?php echo htmlspecialchars("Username") ?></option>
<option value="<?php echo "naziv" ?>"<?php if ($filterfield == "naziv") { echo "selected"; } ?>><?php echo htmlspecialchars("Naziv") ?></option>
<option value="<?php echo "opis" ?>"<?php if ($filterfield == "opis") { echo "selected"; } ?>><?php echo htmlspecialchars("Opis") ?></option>
<option value="<?php echo "kljucne_reci" ?>"<?php if ($filterfield == "kljucne_reci") { echo "selected"; } ?>><?php echo htmlspecialchars("Kljucne reci") ?></option>
<option value="<?php echo "mesto_fotografisanja" ?>"<?php if ($filterfield == "mesto_fotografisanja") { echo "selected"; } ?>><?php echo htmlspecialchars("Mesto fot.") ?></option>
<option value="<?php echo "vreme_fotografisanja" ?>"<?php if ($filterfield == "vreme_fotografisanja") { echo "selected"; } ?>><?php echo htmlspecialchars("Vreme_fot.") ?></option>
<option value="<?php echo "aparat" ?>"<?php if ($filterfield == "aparat") { echo "selected"; } ?>><?php echo htmlspecialchars("Aparat") ?></option>
<option value="<?php echo "objektiv" ?>"<?php if ($filterfield == "objektiv") { echo "selected"; } ?>><?php echo htmlspecialchars("Objektiv") ?></option>
<option value="<?php echo "filteri" ?>"<?php if ($filterfield == "filteri") { echo "selected"; } ?>><?php echo htmlspecialchars("Filteri") ?></option>
<option value="<?php echo "tehnicki_detalji" ?>"<?php if ($filterfield == "tehnicki_detalji") { echo "selected"; } ?>><?php echo htmlspecialchars("Tehnick detalji") ?></option>
<option value="<?php echo "ekspozicija" ?>"<?php if ($filterfield == "ekspozicija") { echo "selected"; } ?>><?php echo htmlspecialchars("Ekspozicija") ?></option>
<option value="<?php echo "blenda" ?>"<?php if ($filterfield == "blenda") { echo "selected"; } ?>><?php echo htmlspecialchars("Blenda") ?></option>
<option value="<?php echo "iso" ?>"<?php if ($filterfield == "iso") { echo "selected"; } ?>><?php echo htmlspecialchars("ISO") ?></option>
<option value="<?php echo "datum_postavljanja" ?>"<?php if ($filterfield == "datum_postavljanja") { echo "selected"; } ?>><?php echo htmlspecialchars("Datum postavljanja") ?></option>
<option value="<?php echo "slika" ?>"<?php if ($filterfield == "slika") { echo "selected"; } ?>><?php echo htmlspecialchars("Slika") ?></option>
<option value="<?php echo "broj_skljoceva" ?>"<?php if ($filterfield == "broj_skljoceva") { echo "selected"; } ?>><?php echo htmlspecialchars("Broj skljoceva") ?></option>
<option value="<?php echo "broj_pregleda" ?>"<?php if ($filterfield == "broj_pregleda") { echo "selected"; } ?>><?php echo htmlspecialchars("Broj pregleda") ?></option>
<option value="<?php echo "galerija" ?>"<?php if ($filterfield == "galerija") { echo "selected"; } ?>><?php echo htmlspecialchars("Galerija") ?></option>
<option value="<?php echo "modelaparata" ?>"<?php if ($filterfield == "modelaparata") { echo "selected"; } ?>><?php echo htmlspecialchars("Model aparata") ?></option>
<option value="<?php echo "autorovkomentar" ?>"<?php if ($filterfield == "autorovkomentar") { echo "selected"; } ?>><?php echo htmlspecialchars("Opis") ?></option>
<option value="<?php echo "broj_favorita" ?>"<?php if ($filterfield == "broj_favorita") { echo "selected"; } ?>><?php echo htmlspecialchars("Broj favorita") ?></option>
<option value="<?php echo "broj_komentara" ?>"<?php if ($filterfield == "broj_komentara") { echo "selected"; } ?>><?php echo htmlspecialchars("Broj komentara") ?></option>
<option value="<?php echo "ver1" ?>"<?php if ($filterfield == "ver1") { echo "selected"; } ?>><?php echo htmlspecialchars("ver1") ?></option>
<option value="<?php echo "ver2" ?>"<?php if ($filterfield == "ver2") { echo "selected"; } ?>><?php echo htmlspecialchars("ver2") ?></option>
<option value="<?php echo "opisver1" ?>"<?php if ($filterfield == "opisver1") { echo "selected"; } ?>><?php echo htmlspecialchars("opisver1") ?></option>
<option value="<?php echo "opisver2" ?>"<?php if ($filterfield == "opisver2") { echo "selected"; } ?>><?php echo htmlspecialchars("opisver2") ?></option>
<option value="<?php echo "objava" ?>"<?php if ($filterfield == "objava") { echo "selected"; } ?>><?php echo htmlspecialchars("objava") ?></option>
</select></td>
<td><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Samo reci</td>
</td></tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="action" value="Postavi filter"></td>
<td><a href="fotografija.php?a=reset">Resetuj filter</a></td>
</tr>
</table>
</form>
<hr size="1" noshade>
<?php showpagenav($page, $pagecount); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<td class="hr">&nbsp;</td>
<td class="hr">&nbsp;</td>
<td class="hr">&nbsp;</td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "username" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Username") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "naziv" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Naziv") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "opis" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Opis") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "kljucne_reci" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Kljucne reci") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "mesto_fotografisanja" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Mesto fot.") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "vreme_fotografisanja" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Vreme_fot.") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "aparat" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Aparat") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "objektiv" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Objektiv") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "filteri" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Filteri") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "tehnicki_detalji" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Tehnick detalji") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "ekspozicija" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Ekspozicija") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "blenda" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Blenda") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "iso" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("ISO") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "datum_postavljanja" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Datum postavljanja") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "slika" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Slika") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "broj_skljoceva" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Broj skljoceva") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "broj_pregleda" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Broj pregleda") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "galerija" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Galerija") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "modelaparata" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Model aparata") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "autorovkomentar" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Opis") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "broj_favorita" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Broj favorita") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "broj_komentara" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Broj komentara") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "ver1" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("ver1") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "ver2" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("ver2") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "opisver1" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("opisver1") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "opisver2" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("opisver2") ?></a></td>
<td class="hr"><a class="hr" href="fotografija.php?order=<?php echo "objava" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("objava") ?></a></td>
</tr>
<?php
  for ($i = $startrec; $i < $reccount; $i++)
  {
    $row = mysql_fetch_assoc($res);
    $style = "dr";
    if ($i % 2 != 0) {
      $style = "sr";
    }
?>
<tr>
<td class="<?php echo $style ?>"><a href="fotografija.php?a=view&recid=<?php echo $i ?>">Pregled</a></td>
<td class="<?php echo $style ?>"><a href="fotografija.php?a=edit&recid=<?php echo $i ?>">Izmene</a></td>
<td class="<?php echo $style ?>"><a href="fotografija.php?a=del&recid=<?php echo $i ?>">Brisanje</a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["username"]) ?></td>
<td class="<?php echo $style ?>"><a href = "http://www.tattooportal.org/velika.php?id=<?php echo htmlspecialchars($row["id"]) ?>" target = "_blank"><?php echo htmlspecialchars($row["naziv"]) ?> (prikaz)</a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["opis"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["kljucne_reci"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["mesto_fotografisanja"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["vreme_fotografisanja"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["aparat"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["objektiv"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["filteri"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["tehnicki_detalji"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["ekspozicija"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["blenda"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["iso"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["datum_postavljanja"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["slika"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["broj_skljoceva"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["broj_pregleda"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["galerija"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["modelaparata"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["autorovkomentar"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["broj_favorita"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["broj_komentara"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["ver1"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["ver2"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["opisver1"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["opisver2"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["objava"]) ?></td>
</tr>
<?php
  }
  mysql_free_result($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount); ?>
<?php } ?>

<?php function showrow($row, $recid)
  {
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("Username")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["username"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Naziv")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["naziv"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Opis")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["opis"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Kljucne reci")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["kljucne_reci"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Mesto fot.")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["mesto_fotografisanja"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Vreme_fot.")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["vreme_fotografisanja"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Aparat")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["aparat"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Objektiv")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["objektiv"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Filteri")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["filteri"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Tehnick detalji")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["tehnicki_detalji"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Ekspozicija")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["ekspozicija"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Blenda")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["blenda"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ISO")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["iso"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Datum postavljanja")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["datum_postavljanja"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Slika")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["slika"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Broj skljoceva")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["broj_skljoceva"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Broj pregleda")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["broj_pregleda"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Galerija")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["galerija"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Model aparata")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["modelaparata"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Opis")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["autorovkomentar"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Broj favorita")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["broj_favorita"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Broj komentara")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["broj_komentara"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ver1")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["ver1"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ver2")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["ver2"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("opisver1")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["opisver1"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("opisver2")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["opisver2"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("objava")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["objava"]) ?></td>
</tr>
</table>
<?php } ?>

<?php function showroweditor($row, $iseditmode)
  {
  global $conn;
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("id")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="id" value="<?php echo str_replace('"', '&quot;', trim($row["id"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Username")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="username" maxlength="20" value="<?php echo str_replace('"', '&quot;', trim($row["username"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Naziv")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="naziv" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["naziv"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Opis")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="opis" maxlength="255"><?php echo str_replace('"', '&quot;', trim($row["opis"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Kljucne reci")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="kljucne_reci" maxlength="255"><?php echo str_replace('"', '&quot;', trim($row["kljucne_reci"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Mesto fot.")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="mesto_fotografisanja" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["mesto_fotografisanja"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Vreme_fot.")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="vreme_fotografisanja" maxlength="30" value="<?php echo str_replace('"', '&quot;', trim($row["vreme_fotografisanja"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Aparat")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="aparat" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["aparat"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Objektiv")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="objektiv" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["objektiv"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Filteri")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="filteri" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["filteri"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Tehnick detalji")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="tehnicki_detalji" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["tehnicki_detalji"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Ekspozicija")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="ekspozicija" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["ekspozicija"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Blenda")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="blenda" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["blenda"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ISO")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="iso" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["iso"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Datum postavljanja")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="datum_postavljanja" value="<?php echo str_replace('"', '&quot;', trim($row["datum_postavljanja"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Slika")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="slika" maxlength="100"><?php echo str_replace('"', '&quot;', trim($row["slika"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Broj skljoceva")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="broj_skljoceva" value="<?php echo str_replace('"', '&quot;', trim($row["broj_skljoceva"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Broj pregleda")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="broj_pregleda" value="<?php echo str_replace('"', '&quot;', trim($row["broj_pregleda"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Galerija")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="galerija" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["galerija"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Model aparata")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="modelaparata" maxlength="50" value="<?php echo str_replace('"', '&quot;', trim($row["modelaparata"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Opis")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="autorovkomentar" maxlength="255"><?php echo str_replace('"', '&quot;', trim($row["autorovkomentar"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Broj favorita")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="broj_favorita" value="<?php echo str_replace('"', '&quot;', trim($row["broj_favorita"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Broj komentara")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="broj_komentara" value="<?php echo str_replace('"', '&quot;', trim($row["broj_komentara"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ver1")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="ver1" maxlength="100"><?php echo str_replace('"', '&quot;', trim($row["ver1"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ver2")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="ver2" maxlength="100"><?php echo str_replace('"', '&quot;', trim($row["ver2"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("opisver1")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="opisver1" maxlength="500"><?php echo str_replace('"', '&quot;', trim($row["opisver1"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("opisver2")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="opisver2" maxlength="500"><?php echo str_replace('"', '&quot;', trim($row["opisver2"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("objava")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="objava" value="<?php echo str_replace('"', '&quot;', trim($row["objava"])) ?>"></td>
</tr>
</table>
<?php } ?>

<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="fotografija.php?a=add">Dodaj podatak</a>&nbsp;</td>
<?php if ($page > 1) { ?>
<td><a href="fotografija.php?page=<?php echo $page - 1 ?>">&lt;&lt;&nbsp;Predhodni</a>&nbsp;</td>
<?php } ?>
<?php
  global $pagerange;

  if ($pagecount > 1) {

  if ($pagecount % $pagerange != 0) {
    $rangecount = intval($pagecount / $pagerange) + 1;
  }
  else {
    $rangecount = intval($pagecount / $pagerange);
  }
  for ($i = 1; $i < $rangecount + 1; $i++) {
    $startpage = (($i - 1) * $pagerange) + 1;
    $count = min($i * $pagerange, $pagecount);

    if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
      for ($j = $startpage; $j < $count + 1; $j++) {
        if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="fotografija.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="fotografija.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td>&nbsp;<a href="fotografija.php?page=<?php echo $page + 1 ?>">Sledeci&nbsp;&gt;&gt;</a>&nbsp;</td>
<?php } ?>
</tr>
</table>
<?php } ?>

<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="fotografija.php">Pocetna strana</a></td>
<?php if ($recid > 0) { ?>
<td><a href="fotografija.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Predhodni podatak</a></td>
<?php } if ($recid < $count - 1) { ?>
<td><a href="fotografija.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Sledeci podatak</a></td>
<?php } ?>
</tr>
</table>
<hr size="1" noshade>
<?php } ?>

<?php function addrec()
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="fotografija.php">Pocetna strana</a></td>
</tr>
</table>
<hr size="1" noshade>
<form enctype="multipart/form-data" action="fotografija.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
  "id" => "",
  "username" => "",
  "naziv" => "",
  "opis" => "",
  "kljucne_reci" => "",
  "mesto_fotografisanja" => "",
  "vreme_fotografisanja" => "",
  "aparat" => "",
  "objektiv" => "",
  "filteri" => "",
  "tehnicki_detalji" => "",
  "ekspozicija" => "",
  "blenda" => "",
  "iso" => "",
  "datum_postavljanja" => "",
  "slika" => "",
  "broj_skljoceva" => "",
  "broj_pregleda" => "",
  "galerija" => "",
  "modelaparata" => "",
  "autorovkomentar" => "",
  "broj_favorita" => "",
  "broj_komentara" => "",
  "ver1" => "",
  "ver2" => "",
  "opisver1" => "",
  "opisver2" => "",
  "objava" => "");
showroweditor($row, false);
?>
<p><input type="submit" name="action" value="Posalji"></p>
</form>
<?php } ?>

<?php function viewrec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<br>
<hr size="1" noshade>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="fotografija.php?a=add">Dodaj podatak</a></td>
<td><a href="fotografija.php?a=edit&recid=<?php echo $recid ?>">Izmeni podatak</a></td>
<td><a href="fotografija.php?a=del&recid=<?php echo $recid ?>">Obrisi podatak</a></td>
</tr>
</table>
<?php
  mysql_free_result($res);
} ?>

<?php function editrec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("edit", $recid, $count);
?>
<br>
<form enctype="multipart/form-data" action="fotografija.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xid" value="<?php echo $row["id"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Posalji"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function deleterec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("del", $recid, $count);
?>
<br>
<form action="fotografija.php" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xid" value="<?php echo $row["id"] ?>">
<?php showrow($row, $recid) ?>
<p><input type="submit" name="action" value="Potvrdi"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function connect()
{
    require_once( 'DBConfig.php' );
    
  $conn = mysql_connect($AdminHost, $AdminUser, $AdminPassword);
  mysql_select_db($AdminDatabase);
  return $conn;
}

function sqlvalue($val, $quote)
{
  if ($quote)
    $tmp = sqlstr($val);
  else
    $tmp = $val;
  if ($tmp == "")
    $tmp = "NULL";
  elseif ($quote)
    $tmp = "'".$tmp."'";
  return $tmp;
}

function sqlstr($val)
{
  return str_replace("'", "''", $val);
}

function sql_select()
{
  global $conn;
  global $order;
  global $ordtype;
  global $filter;
  global $filterfield;
  global $wholeonly;

  $filterstr = sqlstr($filter);
  if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
  $sql = "SELECT `id`, `username`, `naziv`, `opis`, `kljucne_reci`, `mesto_fotografisanja`, `vreme_fotografisanja`, `aparat`, `objektiv`, `filteri`, `tehnicki_detalji`, `ekspozicija`, `blenda`, `iso`, `datum_postavljanja`, `slika`, `broj_skljoceva`, `broj_pregleda`, `galerija`, `modelaparata`, `autorovkomentar`, `broj_favorita`, `broj_komentara`, `ver1`, `ver2`, `opisver1`, `opisver2`, `objava` FROM `fotografija`";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " where (`username` like '" .$filterstr ."') or (`naziv` like '" .$filterstr ."') or (`opis` like '" .$filterstr ."') or (`kljucne_reci` like '" .$filterstr ."') or (`mesto_fotografisanja` like '" .$filterstr ."') or (`vreme_fotografisanja` like '" .$filterstr ."') or (`aparat` like '" .$filterstr ."') or (`objektiv` like '" .$filterstr ."') or (`filteri` like '" .$filterstr ."') or (`tehnicki_detalji` like '" .$filterstr ."') or (`ekspozicija` like '" .$filterstr ."') or (`blenda` like '" .$filterstr ."') or (`iso` like '" .$filterstr ."') or (`datum_postavljanja` like '" .$filterstr ."') or (`slika` like '" .$filterstr ."') or (`broj_skljoceva` like '" .$filterstr ."') or (`broj_pregleda` like '" .$filterstr ."') or (`galerija` like '" .$filterstr ."') or (`modelaparata` like '" .$filterstr ."') or (`autorovkomentar` like '" .$filterstr ."') or (`broj_favorita` like '" .$filterstr ."') or (`broj_komentara` like '" .$filterstr ."') or (`ver1` like '" .$filterstr ."') or (`ver2` like '" .$filterstr ."') or (`opisver1` like '" .$filterstr ."') or (`opisver2` like '" .$filterstr ."') or (`objava` like '" .$filterstr ."')";
  }
  if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
  if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
  $res = mysql_query($sql, $conn) or die(mysql_error());
  return $res;
}

function sql_getrecordcount()
{
  global $conn;
  global $order;
  global $ordtype;
  global $filter;
  global $filterfield;
  global $wholeonly;

  $filterstr = sqlstr($filter);
  if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
  $sql = "SELECT COUNT(*) FROM `fotografija`";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " where (`username` like '" .$filterstr ."') or (`naziv` like '" .$filterstr ."') or (`opis` like '" .$filterstr ."') or (`kljucne_reci` like '" .$filterstr ."') or (`mesto_fotografisanja` like '" .$filterstr ."') or (`vreme_fotografisanja` like '" .$filterstr ."') or (`aparat` like '" .$filterstr ."') or (`objektiv` like '" .$filterstr ."') or (`filteri` like '" .$filterstr ."') or (`tehnicki_detalji` like '" .$filterstr ."') or (`ekspozicija` like '" .$filterstr ."') or (`blenda` like '" .$filterstr ."') or (`iso` like '" .$filterstr ."') or (`datum_postavljanja` like '" .$filterstr ."') or (`slika` like '" .$filterstr ."') or (`broj_skljoceva` like '" .$filterstr ."') or (`broj_pregleda` like '" .$filterstr ."') or (`galerija` like '" .$filterstr ."') or (`modelaparata` like '" .$filterstr ."') or (`autorovkomentar` like '" .$filterstr ."') or (`broj_favorita` like '" .$filterstr ."') or (`broj_komentara` like '" .$filterstr ."') or (`ver1` like '" .$filterstr ."') or (`ver2` like '" .$filterstr ."') or (`opisver1` like '" .$filterstr ."') or (`opisver2` like '" .$filterstr ."') or (`objava` like '" .$filterstr ."')";
  }
  $res = mysql_query($sql, $conn) or die(mysql_error());
  $row = mysql_fetch_assoc($res);
  reset($row);
  return current($row);
}

function sql_insert()
{
  global $conn;
  global $_POST;

  $sql = "insert into `fotografija` (`id`, `username`, `naziv`, `opis`, `kljucne_reci`, `mesto_fotografisanja`, `vreme_fotografisanja`, `aparat`, `objektiv`, `filteri`, `tehnicki_detalji`, `ekspozicija`, `blenda`, `iso`, `datum_postavljanja`, `slika`, `broj_skljoceva`, `broj_pregleda`, `galerija`, `modelaparata`, `autorovkomentar`, `broj_favorita`, `broj_komentara`, `ver1`, `ver2`, `opisver1`, `opisver2`, `objava`) values (" .sqlvalue(@$_POST["id"], false).", " .sqlvalue(@$_POST["username"], true).", " .sqlvalue(@$_POST["naziv"], true).", " .sqlvalue(@$_POST["opis"], true).", " .sqlvalue(@$_POST["kljucne_reci"], true).", " .sqlvalue(@$_POST["mesto_fotografisanja"], true).", " .sqlvalue(@$_POST["vreme_fotografisanja"], true).", " .sqlvalue(@$_POST["aparat"], true).", " .sqlvalue(@$_POST["objektiv"], true).", " .sqlvalue(@$_POST["filteri"], true).", " .sqlvalue(@$_POST["tehnicki_detalji"], true).", " .sqlvalue(@$_POST["ekspozicija"], true).", " .sqlvalue(@$_POST["blenda"], true).", " .sqlvalue(@$_POST["iso"], true).", " .sqlvalue(@$_POST["datum_postavljanja"], true).", " .sqlvalue(@$_POST["slika"], true).", " .sqlvalue(@$_POST["broj_skljoceva"], false).", " .sqlvalue(@$_POST["broj_pregleda"], false).", " .sqlvalue(@$_POST["galerija"], true).", " .sqlvalue(@$_POST["modelaparata"], true).", " .sqlvalue(@$_POST["autorovkomentar"], true).", " .sqlvalue(@$_POST["broj_favorita"], false).", " .sqlvalue(@$_POST["broj_komentara"], false).", " .sqlvalue(@$_POST["ver1"], true).", " .sqlvalue(@$_POST["ver2"], true).", " .sqlvalue(@$_POST["opisver1"], true).", " .sqlvalue(@$_POST["opisver2"], true).", " .sqlvalue(@$_POST["objava"], false).")";
  mysql_query($sql, $conn) or die(mysql_error());
}

function sql_update()
{
  global $conn;
  global $_POST;

  $sql = "update `fotografija` set `id`=" .sqlvalue(@$_POST["id"], false).", `username`=" .sqlvalue(@$_POST["username"], true).", `naziv`=" .sqlvalue(@$_POST["naziv"], true).", `opis`=" .sqlvalue(@$_POST["opis"], true).", `kljucne_reci`=" .sqlvalue(@$_POST["kljucne_reci"], true).", `mesto_fotografisanja`=" .sqlvalue(@$_POST["mesto_fotografisanja"], true).", `vreme_fotografisanja`=" .sqlvalue(@$_POST["vreme_fotografisanja"], true).", `aparat`=" .sqlvalue(@$_POST["aparat"], true).", `objektiv`=" .sqlvalue(@$_POST["objektiv"], true).", `filteri`=" .sqlvalue(@$_POST["filteri"], true).", `tehnicki_detalji`=" .sqlvalue(@$_POST["tehnicki_detalji"], true).", `ekspozicija`=" .sqlvalue(@$_POST["ekspozicija"], true).", `blenda`=" .sqlvalue(@$_POST["blenda"], true).", `iso`=" .sqlvalue(@$_POST["iso"], true).", `datum_postavljanja`=" .sqlvalue(@$_POST["datum_postavljanja"], true).", `slika`=" .sqlvalue(@$_POST["slika"], true).", `broj_skljoceva`=" .sqlvalue(@$_POST["broj_skljoceva"], false).", `broj_pregleda`=" .sqlvalue(@$_POST["broj_pregleda"], false).", `galerija`=" .sqlvalue(@$_POST["galerija"], true).", `modelaparata`=" .sqlvalue(@$_POST["modelaparata"], true).", `autorovkomentar`=" .sqlvalue(@$_POST["autorovkomentar"], true).", `broj_favorita`=" .sqlvalue(@$_POST["broj_favorita"], false).", `broj_komentara`=" .sqlvalue(@$_POST["broj_komentara"], false).", `ver1`=" .sqlvalue(@$_POST["ver1"], true).", `ver2`=" .sqlvalue(@$_POST["ver2"], true).", `opisver1`=" .sqlvalue(@$_POST["opisver1"], true).", `opisver2`=" .sqlvalue(@$_POST["opisver2"], true).", `objava`=" .sqlvalue(@$_POST["objava"], false) ." where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());
}

function sql_delete()
{
  global $conn;

  $sql = "delete from `fotografija` where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());
}
function primarykeycondition()
{
  global $_POST;
  $pk = "";
  $pk .= "(`id`";
  if (@$_POST["xid"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xid"], false);
  };
  $pk .= ")";
  return $pk;
}
 ?>
